package org.xiaoyu.txy.weixin.login.service;

import org.xiaoyu.txy.weixin.BaseService;
import org.xiaoyu.txy.weixin.contant.WXContant;
import org.xiaoyu.txy.weixin.login.model.ReqAuthAccessToken;
import org.xiaoyu.txy.weixin.login.model.ReqCode;
import org.xiaoyu.txy.weixin.login.model.ReqGetAccessToken;
import org.xiaoyu.txy.weixin.login.model.ReqGetUserInfo;
import org.xiaoyu.txy.weixin.login.model.ReqRefreshToken;
import org.xiaoyu.txy.weixin.login.model.ResAuthAccessToken;
import org.xiaoyu.txy.weixin.login.model.ResGetAccessToken;
import org.xiaoyu.txy.weixin.login.model.ResGetRefreshToken;
import org.xiaoyu.txy.weixin.login.model.ResGetUserInfo;
import org.xiaoyu.txy.weixin.util.UrlFormatUtil;

public class WXLoginService extends BaseService{

	/**
	 * 开放平台请求code
	 * @param code
	 * @return
	 */
	public String getCode(ReqCode code){
		return UrlFormatUtil.fullLink(WXContant.OPEN_WX_URL, code) + "#wechat_redirect";	
	}
	
	/**
	 * 公众号请求code
	 * @param code
	 * @return
	 */
	public String getMpCode(ReqCode code){
		return UrlFormatUtil.fullLink(WXContant.MP_WX_URL, code) + "#wechat_redirect";	
	}
	
	/**
	 * 获取accessToken
	 * @param accessToken
	 * @return
	 */
	public ResGetAccessToken getAccessToken(ReqGetAccessToken accessToken){
		return reqInterface(WXContant.GET_ACCESS_TOKEN_URL, accessToken, ResGetAccessToken.class);
	}
	
	/**
	 * 获取刷新accessToken
	 * @param refreshToken
	 * @return
	 */
	public ResGetRefreshToken getRefreshToken(ReqRefreshToken refreshToken){
		return reqInterface(WXContant.REFRSH_ACCESS_TOKEN_URL, refreshToken, ResGetRefreshToken.class);
	}
	
	/**
	 * 鉴定accessToken
	 * @param accessToken
	 * @return
	 */
	public ResAuthAccessToken authAccessToken(ReqAuthAccessToken accessToken){
		return reqInterface(WXContant.AUTH_ACCESS_TOKEN_URL, accessToken, ResAuthAccessToken.class);
	}
	
	/**
	 * 获取用户信息
	 * @param getUserInfo
	 * @return
	 */
	public ResGetUserInfo getUserInfo(ReqGetUserInfo getUserInfo){
		return reqInterface(WXContant.WX_USERINFO_URL, getUserInfo, ResGetUserInfo.class);
	}
	
	
}
